package com.tedu.egsringbootmvc.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@Aspect
public class LogAspect {
    @Before("execution(public com.tedu.egsringbootmvc.common.result.JsonResult com.tedu.egsringbootmvc.controller.*.*(..))")
    public void before(JoinPoint joinPoint){
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().getName();
        log.info(className+"."+methodName+"()开始执行");
    }
    @AfterReturning("execution(public com.tedu.egsringbootmvc.common.result.JsonResult com.tedu.egsringbootmvc.controller.*.*(..))")
    public void afterReturning(JoinPoint joinPoint){
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().getName();
        log.info(className+"."+methodName+"()执行完毕");
    }
    @AfterThrowing(
            value = "execution(public com.tedu.egsringbootmvc.common.result.JsonResult com.tedu.egsringbootmvc.controller.*.*(..))",
            throwing = "throwable"
    )
    public void afterThrowing(JoinPoint joinPoint,Throwable throwable){

        log.error(throwable.getMessage(),throwable);
    }
}
